# Sustainable Office Designer
# by Fabian Ritter <Fabian.Ritter@live.de>, 2012

require 'SOD/tools/Tool'

module SOD
  
  class RemoveFootprintTool < Tool
    
    def initialize
      @cursor = UI.create_cursor(Plugin.dir + "/icons/test.tiff", 3, 3)
    end


    def activate
      super
      Sketchup.active_model.selection.clear
    end
    
    def onMouseMove(flags, x, y, view)
      super
      # Should apply user's precision setting here   --automatically done, I think
      # Also:  show relative coordinates?
      Sketchup.set_status_text("Remove a face from Footprints = " + @ip.position.to_s)
      view.tooltip = "Remove Footprint"
    end


    def onLButtonUp(flags, x, y, view)
      super
      
      model = Sketchup.active_model
      active_path = model.active_path
      
      if @ip.face.get_attribute "SOD_dictionary", "SOD_type" != "Footprint"
        UI.messagebox("No active SOD Footprint")
        return false
      end
      
      if (face = @ip.face)
        
        Plugin.model.footprint.remove(face)
        
        #$g_footprint = face #I think the global variables have to be stored in a Hash. Then they can be accessed for multiple rectangular footprints
        #loop = face.outer_loop
        #pnt0 = loop.vertices[0].position
        #pnt2 = loop.vertices[2].position
        #vec = pnt2 - pnt0
        #g_set_footprint_size(vec.x.to_mm.abs, vec.y.to_mm.abs)
        
      end
      
    end
    
  end
  
end
